home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / misc / emu / Apex-src.lha / MEMBUF.68K < prev    next >
Text File  |  2001-09-30  |  4KB  |  150 lines

  1. ;MEMBUF.68K    MAR-04-89    (ALSO SEE "INFOSTR")
  2. ;Memory buffer handler
  3. ;Written by Loren Blaney for DFM Engineering.
  4. ;
  5. ;REVISION HISTORY:
  6. ;
  7. ;WARNING:
  8. ;If the buffer is not correctly sized, memory can be bombed.
  9. ;
  10.  
  11.     NOLIST
  12.     INCLUDE    SYSPAG
  13.     LIST
  14.  
  15. DEVNUM    EQU    6        ;Device number of this handler
  16.  
  17.     ORG    $0E00
  18. START    EQU    @
  19.  
  20. ;======================================================================
  21. ;ENTRY POINTS:
  22. ;
  23. MEMBUF    DC.L    OPENI        ;$00 = Initialize for input
  24.     DC.L    OPENO        ;$04 = Initialize for output
  25.     DC.L    CHIN        ;$08 = Input byte from buffer
  26.     DC.L    CHOUT        ;$0C = Output byte to buffer
  27.     DC.L    CLOSE        ;$10 = Terminate output
  28.     DC.L    GETINFO        ;$14 = Get info
  29.     DC.L    SETBUF        ;$18 = Set up buffer
  30.  
  31. ;VARIABLES:
  32. BUFFER    DC.L    DEFBUF        ;Pointer to buffer space
  33. BUFEND    DC.L    DEFEND        ;Pointer to end of buffer (+1)
  34. INPTR    DC.L    DEFBUF        ;Pointer to location to read from
  35. OUTPTR    DC.L    DEFBUF        ;Pointer to location to store into
  36.  
  37. ;----------------------------------------------------------------------
  38. ;Reset the input pointer to the start of the buffer
  39. ;
  40. OPENI    MOVE.L    BUFFER.L,INPTR.L
  41.     RTS
  42.  
  43. ;----------------------------------------------------------------------
  44. ;Reset the output pointer to the start of the buffer
  45. ;
  46. OPENO    MOVE.L    BUFFER.L,OUTPTR.L
  47.     RTS
  48.  
  49. ;----------------------------------------------------------------------
  50. ;Get byte from buffer and return it in D0
  51. ; This does not check for reading beyond end of buffer
  52. ;
  53. CHIN    MOVE.L    A6,-(SP)    ;Save A6
  54.  
  55.     MOVEA.L    INPTR.L,A6
  56.     MOVEQ    #0,D0        ;Make sure high bytes are clear
  57.     MOVE.B    (A6)+,D0
  58.  
  59.     CMPA.L    BUFEND.L,A6    ;Is pointer beyond end of buffer?
  60.     BLO.S    CHIN10        ;Branch if not
  61.     JSR    VERROR        ;Flag error
  62.     ASCII    "61 - READ BEYOND END OF BUFFER"
  63.     DC.B    0
  64.     BRA.S    CHIN90        ;Exit
  65. CHIN10
  66.     MOVE.L    A6,INPTR.L    ;Save incremented pointer
  67. CHIN90
  68.     MOVEA.L    (SP)+,A6    ;Restore A6
  69.     RTS
  70.     
  71. ;----------------------------------------------------------------------
  72. ;Output the byte in D0 to the buffer
  73. ;
  74. CHOUT    MOVE.L    A6,-(SP)    ;Save A6
  75.  
  76.     MOVEA.L    OUTPTR.L,A6    ;Get output pointer
  77.     MOVE.B    D0,(A6)+    ;Store byte into buffer
  78.  
  79.     CMPA.L    BUFEND.L,A6    ;Is pointer beyond end of buffer?
  80.     BLO.S    CHOUT10        ;Branch if not
  81.     JSR    VERROR        ;Flag error
  82.     ASCII    "62 - WRITE BEYOND END OF BUFFER"
  83.     DC.B    0
  84.     BRA.S    CHOUT90        ;Exit
  85. CHOUT10
  86.     MOVE.L    A6,OUTPTR.L    ;Save incremented pointer
  87. CHOUT90
  88.     MOVEA.L    (SP)+,A6    ;Restore A6
  89.     RTS
  90.     
  91. ;----------------------------------------------------------------------
  92. ;Output an EOF to the buffer
  93. ;
  94. CLOSE    MOVE.L    D0,-(SP)    ;Save D0
  95.  
  96.     MOVEQ    #EOF,D0
  97.     BSR.S    CHOUT
  98.  
  99.     MOVE.L    (SP)+,D0    ;Restore D0
  100.     RTS
  101.  
  102. ;-----------------------------------------------------------------------
  103. ;Return the address of the information block in D0
  104. ;
  105. GETINFO    MOVE.L    #INFO,D0
  106.     RTS
  107.  
  108. INFO    DC.L    START        ;HANDLER START AND END ADDRESSES
  109.     DC.L    END
  110.     DC.L    INFOSTR
  111. INFOSTR    ASCII    "MEMBUF    MAR-04-89  Memory buffer"
  112.     DC.B    0
  113.  
  114. ;-----------------------------------------------------------------------
  115. ;Set up buffer space
  116. ; Inputs: A0 = Buffer address
  117. ;      D0 = Size in bytes
  118. ;
  119. SETBUF    MOVE.L    A0,BUFFER.L
  120.     MOVE.L    A0,BUFEND.L    ;BUFEND = BUFFER +size +1
  121.     ADD.L    D0,BUFEND.L
  122.     ADDQ.L    #1,BUFEND.L
  123.     BSR    OPENO
  124.     BRA    OPENI        ;(PBRA)
  125.  
  126. ;-----------------------------------------------------------------------
  127. ;Default buffer space
  128. ;
  129. DEFBUF
  130. DEFEND    EQU    START +$200
  131.     DCB.B    DEFEND-@,EOF
  132.  
  133.  
  134. END    EQU    @-1        ;Address where this handler ends
  135.  
  136.     IF    END >= $1000
  137.     ERROR -- PROGRAM IS TOO LONG
  138.     ENDIF
  139.  
  140. ;======================================================================
  141. ;Hook handler into the device handler table
  142. ;
  143.     ORG    4 *DEVNUM +DEVTBL
  144.     DC.L    MEMBUF
  145.  
  146.     END
  147. ===============================
  148. ;Hook handler into the device handler table
  149. ;
  150.     ORG    4